﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entities.Admin;
using System.Text.RegularExpressions;
 
 

namespace BLL.Admin
{
   
  public  class QuanLiNhanVien
    {
      public static List<string> dsthanhpho = new List<string>() { "An Giang", "Bà Rịa Vũng Tàu"
          ,"Bạc Liêu","Bắc Cạn","Bắc Giang","Bắc Ning","Bến Tre","Bình Dương",
          "Bình Định","Bình Phước","Bình Thuận","Cà Mau","Cao Bằng","Cần Thơ (TP)",
          "Đà Na (TP)","Đắk Lắk","Đắk Nông","Điện Biên","Đồng Nai","Đồng Tháp","Gia Lai","Hà Giang","Hà Nam",
          "Hà Nội(TP)","Hà Tĩnh","Hải Dương","Hài Phòng (TP)","Hòa Bình","TP Hồ Chí Minh (TP)","Hậu Giang","Hưng Yên",
          "Khánh Hòa","Kiên Giang","Kom Tum","Lai Châu","Lào Cai","Lạng Sơn","Lâm Đồng","Long An","Nam Định",
          "Nghệ An","Nình Bình","Ninh Thuận","Phú Thọ","Phú Yên","Quảng Bình","Quảng Nam","Quảng Ngãi","Quảng Ninh","Quảng Trị",
          "Sóc Trăng","Sơn La","Tây Ninh","Thái Bình","Thái Nguyên","Thanh Hóa","Thừa Thiên-Huế","Tiền Giang","Trà Vinh",
           	"Tuyên Quang","Vĩnh Long","Vĩnh Phúc","Yên Bái"};

  
      public static void LoadCbBoPhan(ComboBox cb, List<BoPhan> ds)
      {
          cb.Items.Clear();
          foreach (var bp in ds)
              cb.Items.Add(bp);
          cb.DisplayMember = "TenBoPhan";
          cb.ValueMember = "MaBoPhan";
          cb.Items.Insert(0, "-- Bộ Phận --");
          cb.SelectedIndex = 0;


      }
      public static bool KiemTra(string k, List<NhanVien> ds)
      {
          foreach (var item in ds)
              if (item.MaNhanVien.Trim().ToLower().CompareTo(k.Trim().ToLower()) == 0)
                  return true;
          return false;
         
      }

   
      public static List<NhanVien> SapXepTang(List<NhanVien> ds )
      {
         ds.Sort(delegate(NhanVien o, NhanVien b)
          {
              if (o.TenNhanVien.CompareTo(b.TenNhanVien) != 0)
                  return o.TenNhanVien.CompareTo(b.TenNhanVien);
              else return -o.NamSinh.CompareTo(b.NamSinh);
          });
          
         return ds;
      }
      public static List<NhanVien> SapXepGiam( List<NhanVien> ds )
      {
          ds.Sort(delegate(NhanVien o, NhanVien b)
          {
              if (o.TenNhanVien.CompareTo(b.TenNhanVien) != 0)
                  return -o.TenNhanVien.CompareTo(b.TenNhanVien);
              else return o.NamSinh.CompareTo(b.NamSinh);
          });
        
          return ds;
      }
      public static bool KiemTraMaNhanVien(string k)
      {
          if (k.Substring(0, 3).ToUpper() == "NV_" && k.Length>3)
              return true;
          return false;
      }
      public static bool TestInt(string s)
      {
          try
          {
              
              Convert.ToInt32(s);
              return true;
          }
          catch (Exception)
          {

              return false;  
          }
      }
      public static bool KiemTraSoDT(string s)
      {
           

          string paren = @"^0([1-9]{1}\d{8,9})";
          string dtban=@"\(?\b[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{3,4}\b";
          Regex ds=new Regex(dtban,RegexOptions.IgnoreCase);
          Regex rs = new Regex(paren, RegexOptions.IgnoreCase);
          if (rs.IsMatch(s) && s.Length<=11 || ds.IsMatch(s))
              return true;
          return false;

      }
      public static bool KiemTraEamil(string s)
      {

          string paren = "^[A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$";

          Regex rs = new Regex(paren);
          if (rs.IsMatch(s) )
              return true;
          return false;

      }
       
    }
}
